<html>
<head>
	<title>modularjs Test</title>
	<style type="text/css">
		div.error { color: red; }
		div.ok { color: green; }
	</style>
	<script type="text/javascript" src="Module1.js"></script>
	<script type="text/javascript" src="include.js?Module2,Module3,Module4,ModuleA"></script>
	<script type="text/javascript">
		var log = function(class_, message) {
			var e = document.getElementById("messages");

			e.innerHTML += "<div class=\"" + class_ + "\">" + message + "</div>";
		}

		var assert = function(correct, message, errorMessage) {
			if (!errorMessage) {
				errorMessage = "ERROR";
			}

			if (correct) {
				log("ok", message + ": OK");
			} else {
				log("error", message + ", ERROR: " + errorMessage);
			}
		}

		var assertEquals = function(expected, actual, message) {
			assert(actual == expected, message, "Result: " + actual + ", expected: " + expected);
		}

		var assertNotEquals = function(expected, actual, message) {
			assert(actual != expected, message, "Result: " + actual + ", expected different from: " + expected);
		}

		var test = function() {
			log("", "Tests starting");

			assertNotEquals("undefined", typeof modularjs, "modularjs included");
			assertNotEquals("undefined", typeof modularjs.include, "modularjs.include is defined");
			assertNotEquals("undefined", typeof include, "include function is defined");

			assertNotEquals("undefined", typeof Module1, "Module1 loaded");

			assertEquals(typeof Module1, typeof Module2,
				"Variable defined in Module2");
			assertEquals(typeof Module1WithoutVar, typeof Module2WithoutVar,
				"Variable defined in Module2 without using 'var'");
			assertEquals(typeof Module1WithEval, typeof Module2WithEval,
				"Variable defined in Module2 using eval");
			assertEquals(typeof Module1WithEvalWithoutVar, typeof Module2WithEvalWithoutVar,
				"Variable defined in Module2 using eval without using 'var'");

			assertEquals(typeof Module1, typeof Module3,
				"Variable defined in Module3 build");
			assertEquals(typeof Module1, typeof Module4,
				"Variable defined in Module4 compressed build");

			assertNotEquals("undefined", typeof ModuleA, "Variable defined in ModuleA");
			assertNotEquals("undefined", typeof ModuleB, "Variable defined in ModuleB, included from ModuleA");

			assertEquals("undefined", typeof ModuleC, "ModuleC not yet included");
            try {
    			include("ModuleC");
            } catch(e) {
    			assertEquals("No error", e, "Error importing ModuleC");
            }
			assertNotEquals("undefined", typeof ModuleC, "ModuleC included");

			log("", "Tests completed");
		}
	</script>
</head>
<body onload="test()">
	<h1>modularjs Test Suite</h1>
	<div id="messages"></div>
</body>
</html>

